package com.ydy.data.controller;

import com.ydy.common.BaseController;
import com.ydy.common.model.Permissions;
import com.ydy.common.model.User;
import com.ydy.common.util.ParamsUtil;
import com.ydy.common.vo.PageInfo;
import com.ydy.data.service.PermissionInfoService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
public class PermissionInfoController extends BaseController {


    @Autowired
    private PermissionInfoService permissionInfoService;

    /**
     * 查询权限信息
     * @Title: queryPermissionInfo
     * @author: dy.yin 2021/4/2 10:06
     * @param: [request]
     * @return: java.lang.Object
     * @throws
     */
    @GetMapping("/queryPermissionInfo")
    public Object queryPermissionInfo(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        Permissions permissions = ParamsUtil.getBeanParam(new Permissions(),request);

        List<Permissions> permissionList = permissionInfoService.queryPermissionInfo(permissions,pageInfo);
        pageInfo.setPageResult(permissionList);
        return pageInfo;
    }

    /**
     * 新增或者修改权限
     * @param permissions
     * @return
     */
    @PostMapping("/submitPermissionInfo")
    public Object submitPermissionInfo(@RequestBody Permissions permissions){
        permissionInfoService.submitPermissionInfo(permissions);
        return retResultVo();
    }

    /**
     * 删除权限
     * @param map
     * @return
     */
    @PostMapping("/deletePermissionInfo")
    public Object deletePermissionInfo(@RequestBody LinkedHashMap<String,Object> map){
        String permissionCode = MapUtils.getString(map,"permissionCode");
        permissionInfoService.deletePermissionInfo(permissionCode);
        return retResultVo();
    }
}
